//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public class Camera : IOfficeXmlSerializable
    {
        private const int defaultFov = 100;

        private SphereCoordinates coordinates;
        private int fieldOfView;

        private PresetCameraType preset;
        private int zoom = 100000;

        public SphereCoordinates Coordinates
        {
            get { return coordinates; }
            set { coordinates = value; }
        }

        public PresetCameraType Preset
        {
            get { return preset; }
            set { preset = value; }
        }

        public int FieldOfView
        {
            get { return fieldOfView; }
            set { fieldOfView = value; }
        }

        public int Zoom
        {
            get { return zoom; }
            set { zoom = value; }
        }

        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("camera"))
            {
                Preset = c.GetEnum<PresetCameraType>("prst");
                FieldOfView = c.GetOptionalInteger("fov", defaultFov); //\\default?
                Zoom = c.GetOptionalInteger("zoom", 100000);
                Coordinates = c.ReadOptionalElement<SphereCoordinates>("rot");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("camera"))
            {
                c.SetEnum("prst", Preset);
                c.SetOptionalInteger("fov", FieldOfView, defaultFov); //\\default?
                c.SetOptionalInteger("zoom", Zoom, 100000);
                c.WriteOptionalElement(Coordinates);
            }
        }

        #endregion
    }
}